//
//  CardView.m
//  YSLDraggingCardContainerDemo
//
//  Created by yamaguchi on 2015/11/09.
//  Copyright © 2015年 h.yamaguchi. All rights reserved.
//

#import "CardView.h"

@implementation CardView

- (instancetype)init {
    self = [super init];
    if (self) {
        [self setup];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setup];
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self setup];
    }
    return self;
}

- (void)setup
{
//    self.layer.cornerRadius=6;
    self.layer.shadowColor=[UIColor grayColor].CGColor;
    self.layer.shadowOffset=CGSizeMake(1, 6);
    self.layer.shadowOpacity=0.5;
    self.layer.shadowRadius=8;
  
    self.backgroundColor = [UIColor whiteColor];
    
    _imageView = [[UIImageView alloc]init];
    _imageView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height-84*SCREEN_WIDTH_RATIO47);
    [self addSubview:_imageView];

    
    _playerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _playerBtn.frame  = CGRectMake(_imageView.centerX-30, _imageView.centerY-30, 60*SCREEN_WIDTH_RATIO47, 60*SCREEN_WIDTH_RATIO47);
    [_playerBtn setImage:[UIImage imageNamed:@"home_play_icon"] forState:UIControlStateNormal];
    _playerBtn.hidden = YES;
    [_playerBtn addTarget:self action:@selector(PlayVideo) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_playerBtn];
    
    
    UIBezierPath *maskPath;
    maskPath = [UIBezierPath bezierPathWithRoundedRect:_imageView.bounds
                                     byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight)
                                           cornerRadii:CGSizeMake(7.0, 7.0)];
    
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = _imageView.bounds;
    maskLayer.path = maskPath.CGPath;
    _imageView.layer.mask = maskLayer;
    self.imageView.contentMode = UIViewContentModeScaleAspectFill;
    
    
    //左右按钮
    _rightImg = [[UIImageView alloc] initWithFrame:CGRectMake(30, 30, self.width/5, self.width/5)];
    _leftImg = [[UIImageView alloc] initWithFrame:CGRectMake(self.right-30-self.width/4,30, self.width/5, self.width/5)];
    _rightImg.image = [UIImage imageNamed:@"xihuan"];
    _leftImg.image = [UIImage imageNamed:@"wugan"];
    self.rightImg.alpha = 0;
    self.leftImg.alpha = 0;
    [self addSubview:_rightImg];
    [self addSubview:_leftImg];
    
    //蒙层
//    _selectedView = [[UIView alloc]init];
//    _selectedView.frame = _imageView.frame;
//    _selectedView.backgroundColor = [UIColor clearColor];
//    _selectedView.alpha = 0.0;
 
    
    _Namelabel = [[UILabel alloc]init];
    _Namelabel.backgroundColor = [UIColor clearColor];
    if (iPhone6p) {
        _nametitleSize = 19;
        _btntitleSize = 13;
        
    }else if (iPhone6) {
        _nametitleSize = 18;
        _btntitleSize = 12;

    }else if(iPhone5) {
        _nametitleSize = 17;
        _btntitleSize = 11;

    }else{
        _nametitleSize = 19;
        _btntitleSize = 13;
    }
    [_Namelabel sizeToFit];
    _Namelabel.font = FontP(_nametitleSize);

    [self addSubview:_Namelabel];
    
//    CGFloat TopsegmentFloat;
//    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad){
//        NSLog(@"ipad");
//        TopsegmentFloat =379*SCREEN_WIDTH_RATIO47;
//    }else{
//        TopsegmentFloat = 429*SCREEN_WIDTH_RATIO47;
//        NSLog(@"iphone or ipod");
//    }
//    
//    
    
    [_Namelabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_imageView.mas_bottom).offset(15*SCREEN_WIDTH_RATIO47);
        make.left.equalTo(self).offset(15*SCREEN_WIDTH_RATIO47);
        make.height.mas_equalTo(25*SCREEN_WIDTH_RATIO47);
    }];
    
    _sexAgeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _sexAgeBtn.enabled = NO;
    _sexAgeBtn.layer.cornerRadius = 4;
    _sexAgeBtn.layer.masksToBounds = YES;
    _sexAgeBtn.titleLabel.font = FontBold(_btntitleSize);
    [_sexAgeBtn setTitleColor:Theme_Color_White forState:UIControlStateNormal];
   _sexAgeBtn .imageEdgeInsets = UIEdgeInsetsMake(0,-5,0,0);//设置image在button上的位置（上top，左left，下bottom，右right）这里可以写负值，对上写－5，那么image就象上移动5个像素
    _sexAgeBtn.titleEdgeInsets = UIEdgeInsetsMake(0,0,0,0);

    [self addSubview:_sexAgeBtn];
    [_sexAgeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_Namelabel.mas_right).offset(15*SCREEN_WIDTH_RATIO47);
        make.height.mas_equalTo(20*SCREEN_WIDTH_RATIO47);
        make.top.equalTo(_imageView.mas_bottom).offset(18*SCREEN_WIDTH_RATIO47);
        make.width.mas_equalTo(50*SCREEN_WIDTH_RATIO47);
    }];
    
    _constellationLab = [[UILabel alloc] init];
    _constellationLab.font = FontBold(_btntitleSize);
    _constellationLab.textColor = Theme_Color_White;
    _constellationLab.layer.cornerRadius = 4;
    _constellationLab.layer.masksToBounds = YES;
    

    _constellationLab.textAlignment = NSTextAlignmentCenter;
    
    [self addSubview:_constellationLab];
    [_constellationLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_sexAgeBtn.mas_right).offset(5*SCREEN_WIDTH_RATIO47);
        make.height.mas_equalTo(20*SCREEN_WIDTH_RATIO47);
        make.top.equalTo(_imageView.mas_bottom).offset(18*SCREEN_WIDTH_RATIO47);
        make.width.mas_equalTo(50*SCREEN_WIDTH_RATIO47);
    }];
    
    //属相暂时不要
//    _AnimalImg = [[UIImageView alloc] initWithFrame:CGRectMake(self.right-50, _imageView.bottom+23, 25, 25)];
//    [self addSubview:_AnimalImg];
//    [_AnimalImg mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(_imageView.mas_bottom).offset(18);
//        make.right.equalTo(self).offset(-25);
//        make.width.mas_equalTo(25);
//        make.height.mas_equalTo(25);
//    }];
//    self.AnimalImg.contentMode = UIViewContentModeScaleAspectFill;

    _coordinatesImg = [[UIImageView alloc] init];
    [self addSubview:_coordinatesImg];
    [_coordinatesImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_Namelabel.mas_bottom).offset (8*SCREEN_WIDTH_RATIO47);
        make.left.equalTo(self).offset(15*SCREEN_WIDTH_RATIO47);
        make.height.mas_equalTo(18*SCREEN_WIDTH_RATIO47);
        make.width.mas_equalTo(18*SCREEN_WIDTH_RATIO47);
    }];
    
    _coordinatesImg.image = [UIImage imageNamed:@"placeholder_date"];

    _detailsLab = [[UILabel alloc] init];
    _detailsLab.font = FontP(12);
    _detailsLab.textAlignment = NSTextAlignmentLeft;
    _detailsLab.textColor = [UIColor grayColor];
    
    [self addSubview:_detailsLab];
    [_detailsLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_Namelabel.mas_bottom).offset (10*SCREEN_WIDTH_RATIO47);
        make.left.equalTo(_coordinatesImg.mas_right).offset(5*SCREEN_WIDTH_RATIO47);
        make.height.mas_equalTo(18*SCREEN_WIDTH_RATIO47);
    }];
    self.likeCountButton = [[UIButton alloc] init];
    self.likeCountButton.layer.masksToBounds = YES;
    self.likeCountButton.layer.borderColor = [UIColor whiteColor].CGColor;
    self.likeCountButton.layer.borderWidth = 1.5;
    self.likeCountButton.enabled = NO;
    self.likeCountButton.titleLabel.font = FontP(12);
    
    [self.likeCountButton setBackgroundImage:[UIImage imageNamed:@"home_like_button"] forState:UIControlStateNormal];
    [self.likeCountButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    [self addSubview:_likeCountButton];
    
    [_likeCountButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_imageView.mas_right).offset(-10*SCREEN_WIDTH_RATIO47);
        make.height.mas_equalTo(24*SCREEN_WIDTH_RATIO47);
        make.width.mas_equalTo(95*SCREEN_WIDTH_RATIO47);
        make.bottom.equalTo(_imageView.mas_bottom).offset(-10*SCREEN_WIDTH_RATIO47);
    }];
    self.likeCountButton.layer.cornerRadius = 12*SCREEN_WIDTH_RATIO47;


}
//播放
- (void)PlayVideo{

    
    if ([self.delegate respondsToSelector:@selector(playBtnVideoView:)]) {
        [self.delegate playBtnVideoView:_playerVideo];
    }

        [self.playerVideo play];
        self.playerVideo.hidden = NO;
        _imageView.hidden = YES;
        _playerBtn.hidden = YES;
    

}




@end
